<template>
    <div class="quan-main">
        <!-- 面包屑导航 -->
        <div class="breadcrumb">
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item :to="{ path: '/admin/set' }">设置</el-breadcrumb-item>
                <el-breadcrumb-item>轮播图管理</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="quan-body">
            <div class="slide-img">
                <div class="slide-img-info" v-for="(item,index) in slideImg" :key="index">
                    <div class="img-info">
                        <img :src="item.slideImg" alt="">
                        <p :title="item.slideImgUrl">{{item.slideImgUrl}}</p>
                    </div>
                    <div class="oper">
                        <span class="el-icon-zoom-in" @click="showBigImage(item.slideImg)"></span>
                        <span style="margin-left:30px" class="el-icon-delete" @click="deleteImage(item)"></span>
                    </div>
                </div>
                <div class="slide-img-upload" @click="addSlideImg">
                    <i class="el-icon-plus"></i>
                </div>
            </div>
        </div>
        <!-- 组件 -->
        <el-dialog :title="dialogTitle" :visible.sync="dialogFormVisible" :modal-append-to-body="true" :append-to-body='true' :center="true" :show-close="false" width="360px" :close-on-click-modal="false" :close-on-press-escape="false">
            <component v-bind:is="dialogCurrentComponent" @dialogCancel="dialogCancel" @dialogSubmit="dialogSubmit"></component>
        </el-dialog>
    </div>
</template>
<script>
// 发请求全部导入
import api from '@/api/setSlideImg/index'
// 工具
import tool from '@/utils/tool'
// 组件
import setSlideImgAdd from '@/views/admin/setSlideImgAdd'
export default {
    components:{
        setSlideImgAdd
    },
    data() {
        return {
            // 图片数组
            slideImg:[],

            // 图片放大
            // 接受的数组
            viewUrl:[],

            // dailog
            dialogTitle:'',
            dialogFormVisible:false,
            dialogCurrentComponent:'',
        }
    },
    methods: {
        // 得到数据
        getList(){
            api.getList().then(res=>{
                // console.log(res)
                if(res.code !== 200)return
                // if(!res.data || res.data.length<1) return
                this.slideImg = res.data
            })
        },
        // 新增
        addSlideImg(){
            this.dialogTitle = '新增轮播图'
            this.dialogCurrentComponent = 'setSlideImgAdd'
            this.dialogFormVisible = true
        },
        // 删除
        deleteImage(item){
            this.$confirm("确定删除这一项吗?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(() => {
                api.deleteSlideImg(item).then(res => {
                    console.log(res)
                    if(res.code !== 200) return;
                    this.$message({ message: "操作成功！", type: "success" });
                    this.getList();
                });
            }).catch(()=>{})
        },
        // 取消
        dialogCancel(){
            this.dialogFormVisible = false;
            this.dialogCurrentComponent = '';
        },
        // 提交
        dialogSubmit(){
            // 取消
            this.dialogCancel();
            // 刷新
            this.getList();
        },
        // 放大图片
        showBigImage(url){
            this.viewUrl = []
            this.viewUrl.push(url)
            // console.log(this.viewUrl)
            window.createPreview(this.viewUrl)
        }
    },
    created() {
        this.getList()
    },
    mounted() {
        
    },
}
</script>
<style lang="less" scoped>
.slide-img{
    position: relative;
    padding: 60px 60px;
    .slide-img-info{
        position: relative;
        display: inline-block;
        width: 260px;
        height: 200px;
        margin-right: 39px;
        margin-bottom: 39px;
        .img-info{
            width: 260px;
            height: 180px;
            img{
                display: block;
                border-radius: 10px;
                width: 100%;
                height: 100%;
            }
            p{
                text-align: center;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
        }
        .oper{
            position: absolute;
            width: 260px;
            height: 180px;
            top: 0;
            left: 0;
            border-radius: 10px;
            transition: all 0.3s ease;
            text-align: center;
            color: #fff;
            background-color: rgba(0, 0, 0, .5);
            padding-top: 80px;
            box-sizing: border-box;
            opacity: 0;
            cursor: pointer;
        }
        .oper:hover{
            opacity: 1;
        }
    }
    // .slide-img-info:nth-child(4){
    //     margin: 0;
    // }
    .slide-img-upload{
        display: inline-block;
        width: 260px;
        height: 180px;
        box-sizing: border-box;
        border: 1px dashed #d9d9d9;
        transition: all .3s ease;
        vertical-align: top;
        border-radius: 10px;
        i{
            margin-left: 50%;
            transform: translateX(-50%);
            line-height: 180px;
            font-size: 20px;
            color: #d9d9d9;
            transition: all .3s ease;
        }
    }
    .slide-img-upload:hover{
        border: 1px dashed #00e28b;
        i{
            color: #00e28b;
        }
    }
}
// 是不是可以滚动
// .quan-body{
//     overflow-y: auto;
// }
</style>